Skip to content

fix(secrets): respect AWS_REGION for secret lookups#26

Merged
hampsterx merged 1 commit into
masterfrom
fix/secrets-helper-region-resolution
Jun 24, 2026
Merged

fix(secrets): respect AWS_REGION for secret lookups#26
hampsterx merged 1 commit into
masterfrom
fix/secrets-helper-region-resolution

Conversation

@hampsterx

@hampsterx hampsterx commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make Secrets Manager region resolution honor AWS_REGION when boto3 has no session region.
  • Remove the silent ap-southeast-2 fallback so missing region config fails with an explicit error.
  • Cover the local-run fallback and missing-region failure paths in secrets_helper tests.

Review

  • Internal: clean, no findings in the committed diff.
  • External: Kimi review was not run because tenant policy rejected sending private repo diff/file contents to an external service.
  • Static analysis: ruff check nui_shared_utils/secrets_helper.py tests/test_secrets_helper.py reports pre-existing F841 issues in tests/test_secrets_helper.py outside this change.

Changes

  • nui_shared_utils/secrets_helper.py: resolve Secrets Manager region from boto3 session, AWS_REGION, then AWS_DEFAULT_REGION; raise a clear error if none is configured.
  • tests/test_secrets_helper.py: add coverage for AWS_REGION fallback and missing-region failure.

Test plan

  • black nui_shared_utils/secrets_helper.py tests/test_secrets_helper.py
  • pytest tests/test_secrets_helper.py -q
  • pytest tests/test_slack_client.py::TestSendFile -q
  • pytest -q blocked locally by missing snowflake-sql-api; also shows two order-dependent Slack file-upload failures that pass in isolation.

Summary by CodeRabbit

  • Bug Fixes

    • Improved secret retrieval to use the AWS region from the active session or environment variables, instead of relying on a fixed fallback region.
    • Added a clear error when no AWS region is available, helping prevent misconfigured secret lookups.
  • Tests

    • Expanded test coverage for region fallback behavior and the no-region error case.
    • Updated formatting in existing environment-based test setup.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@hampsterx, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 35 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e88009a-d2e0-4206-9b3a-50e366d3385c

📥 Commits

Reviewing files that changed from the base of the PR and between c427f13 and acf0167.

📒 Files selected for processing (2)
  • nui_shared_utils/secrets_helper.py
  • tests/test_secrets_helper.py

Walkthrough

get_secret now resolves the AWS region from the boto3 session or environment variables before creating the Secrets Manager client. Tests add coverage for the fallback and missing-region paths.

Changes

AWS region selection for secrets

Layer / File(s) Summary
Region resolution in get_secret
nui_shared_utils/secrets_helper.py
get_secret resolves the Secrets Manager region from the boto3 session or environment variables and raises when no region is available.
Tests for fallback and missing region
tests/test_secrets_helper.py
Tests verify the AWS_REGION fallback, the missing-region exception path, and the Elasticsearch credentials patch layout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hopped through AWS haze,
Found regions by moonlight and sun’s warm blaze.
No fallback hop to faraway sand,
Just tests in hand and secrets well planned.
🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: secret lookup region resolution now respects AWS_REGION.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/secrets-helper-region-resolution

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • LINEAR integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands.

@hampsterx

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
nui_shared_utils/secrets_helper.py (1)

45-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid hardcoding the AWS service name in get_secret.

Line 45 hardcodes "secretsmanager"; this violates the repository rule to pass service names via parameters/configuration.

As per coding guidelines, **/*.py: "No hardcoded organization-specific values (service names, currencies, business logic) - accept values as parameters or via configuration instead".

Proposed change
-def get_secret(secret_name: str) -> Dict:
+def get_secret(secret_name: str, service_name: str = "secretsmanager") -> Dict:
@@
-    client = session.client(service_name="secretsmanager", region_name=region)
+    client = session.client(service_name=service_name, region_name=region)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nui_shared_utils/secrets_helper.py` at line 45, The get_secret helper
currently hardcodes the AWS service name in the session.client call, which
should instead come from configuration or a parameter. Update get_secret in
secrets_helper.py to accept the service name as an argument (or read it from
config) and pass that through to session.client, so the function no longer
embeds "secretsmanager" directly.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@nui_shared_utils/secrets_helper.py`:
- Line 45: The get_secret helper currently hardcodes the AWS service name in the
session.client call, which should instead come from configuration or a
parameter. Update get_secret in secrets_helper.py to accept the service name as
an argument (or read it from config) and pass that through to session.client, so
the function no longer embeds "secretsmanager" directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec69d16f-2b96-427e-9395-0111f514011d

📥 Commits

Reviewing files that changed from the base of the PR and between d0af0b6 and c427f13.

📒 Files selected for processing (2)
  • nui_shared_utils/secrets_helper.py
  • tests/test_secrets_helper.py

Comment thread tests/test_secrets_helper.py
- Make Secrets Manager region resolution honor AWS_REGION when boto3 has no session region.
- Remove the silent ap-southeast-2 fallback so missing region config fails with an explicit error.
- Cover the local-run fallback and missing-region failure paths in secrets_helper tests.
@hampsterx hampsterx force-pushed the fix/secrets-helper-region-resolution branch from c427f13 to acf0167 Compare June 24, 2026 20:40
@hampsterx hampsterx merged commit 342b24b into master Jun 24, 2026
9 checks passed
@hampsterx hampsterx deleted the fix/secrets-helper-region-resolution branch June 24, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant